package BasicClass;

import javafx.concurrent.Task;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Time extends Task<String> {
    public String time = "";
    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
    private boolean flag = true;

    @Override
    public void run() {
        super.run();
        while (flag) {
            Date date = new Date(System.currentTimeMillis());
            updateMessage(formatter.format(date));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
        }
    }

    @Override
    protected String call() {
        Date date = new Date(System.currentTimeMillis());
        time = formatter.format(date);
        return time;
    }

    public void stop() {
        flag = false;
    }
}
